package ch.uzh.ifi.seal.ssqa.ui.views;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class GenericListView extends ViewPart {
	public static final String ID = "ch.uzh.ifi.seal.ssqa.ui.views.GenericListView";
	
	private TableViewer viewer;
	
	@Override
	public void createPartControl(Composite parent) {
		
		
		
		GridLayout layout = new GridLayout(2, false);
		parent.setLayout(layout);
		Label queryLabel = new Label(parent, SWT.NONE);	
		queryLabel.setText("SQL query from ClearQuest: ");
		final Text queryText = new Text(parent, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		queryText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL 
				| GridData.HORIZONTAL_ALIGN_FILL));
		createViewer(parent);
	}

	@Override
	public void setFocus() {
		

	}

	private void createViewer(Composite parent){
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		createColumns(parent, viewer);
		final Table table = viewer.getTable();
		table.setHeaderVisible(true);
		table.setLinesVisible(true);
		
		viewer.setContentProvider(new ArrayContentProvider());
		viewer.setInput(null);
		getSite().setSelectionProvider(viewer);
		
		
		GridData gridData = new GridData();
		gridData.verticalAlignment = GridData.FILL;
		gridData.horizontalSpan = 2;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		gridData.horizontalAlignment = GridData.FILL;
		viewer.getControl().setLayoutData(gridData);
		
	}
	

	private void createColumns(Composite parent, TableViewer viewer2) {
		// TODO Auto-generated method stub
		
	}

	
	
}
